<template>
    <div id="login">
        <el-form ref="form" :rules="rules" :model="form" class="loginContainer">
            <h3 class="loginTitle">系统登陆</h3>
            <el-form-item prop="name">
                <el-input type="text" auto-complete="false" v-model="form.name" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input type="password" auto-complete="false" v-model="form.password" placeholder="请输入密码"></el-input>
            </el-form-item>
            <el-form-item class="code" prop="code">
                <el-input type="text" auto-complete="false" v-model="form.code" placeholder="点击更换验证码"></el-input>
                <img :src="captchaUrl">
            </el-form-item>
            <el-checkbox class="remember" v-model="checked">记住我</el-checkbox>
            <el-button type="primary" style="width: 100%" @click="login">登陆</el-button>
        </el-form>
    </div>
</template>,

<script>
    export default {
        name: "Login",
        data() {
            return{
                captchaUrl: '',
                checked: true,
                form: {
                    name: 'admin',
                    password: '123',
                    code: ''
                },
                rules: {
                    name: [{required: true,message: '请输入用户名',trigger:'blur'}],
                    password: [{required: true,message: '请输入密码',trigger: 'blur'}],
                    code: [{required: true,message: '请输入验证码',trigger: 'blur'}]
                }
            }
        },
        methods: {
            login(){
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.$message({
                            message: '登陆成功',
                            type: 'success'
                        })
                        this.$router.push('/')
                    } else {
                        this.$message({
                            message: '请输入所有字段!',
                            type: 'warning'
                        })
                        return false
                    }
                })
            }
        }
    }
</script>

<style>
    .loginContainer{
        border-radius: 15px;
        background-clip: padding-box;
        margin: 100px auto;
        width: 350px;
        padding: 15px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
    }
    .loginTitle{
        margin: 0px auto 40px auto;
        text-align: center;
    }
    .code{
        width: 200px;
        margin-right: 5px;
    }
    .remember{
        text-align: left;
        /*四个的话是外边距顺序为：上右下左，顺时针来记忆*/
        margin: 0px 0px 15px 0px;
    }
</style>
